package com.gx.auth.controller;

import com.gx.auth.common.AjaxResult;
import com.gx.auth.entity.User;
import com.gx.auth.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Collection;

/**
 * Created by Administrator on 2017/4/4.
 */
@RequestMapping("/user")
@Controller
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 用户首页
     * @return
     */
    @RequestMapping("/index")
    public String userList(){
        return "/security/user/user_list";
    }

    @PostMapping("/addEditUser")
    @ResponseBody
    public AjaxResult addEditUser(User user){
        if (null == user.getId()){
            userService.addUser(user);
        }else {
            userService.updateUser(user);
        }
        return AjaxResult.success();
    }

    @PostMapping("/deleteUser")
    @ResponseBody
    public AjaxResult dleteUser(Long id){
        userService.deleteUser(id);
        return AjaxResult.success();
    }


    /**
     * 分页查询用户信息
     * @param page
     * @param size
     * @return
     */
    @PostMapping("getUsers")
    @ResponseBody
    public Collection<User> getUsers(Integer page,Integer size){
        return userService.getUsers(page,size);
    }




}
